<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>

    var obj = {
        num:1,
        fn:() => {
            console.log(`this:`,this) //强行绑定上下文window
        },
        fn1:function (){
            console.log(`this:`,this) //谁调用就指向谁
        },
    }
    obj.fn()
    obj.fn1()

    let obj1 = {
        num:2,
        fn:() => {
            console.log(`this:`,this) //强行绑定上下文window
        }
    }
    obj1.fn()

    let obj2 = {
        num:3,
        fn: function (){
            let s = () => {
                console.log(`this:`,this) //强行绑定到上下文父级函数fn的作用域，obj2
            }
            s()
        }
    }
    obj2.fn()

    setTimeout(()=>{
        console.log("这是第一个延时定时器")
        console.log(this) //强行绑定上下文window
    },1000)

    setTimeout(function(){
        console.log("这是第二个延时定时器")
        let o = ()=>{
            console.log(this) //强行绑定上下文window
        }
        o()
    },1500)

    const obj3 ={
        test:function (){ //test函数
            setTimeout(()=>{
                console.log("这是第3个延时定时器")
                console.log(this) //强行绑定上下文父级函数test的this test函数被obj3调用 指向obj3
            },2000)

            setTimeout(function (){ //无名延时定时器函数
                console.log("这是无名延时定时器")
                console.log(this) //谁调用指向谁 没人调用 指向window

                setTimeout(()=>{
                    console.log("这是无名延时定时器的子定时器")
                    console.log(this) //强行绑定上下文this 上下文是无名延时定时器函数的this 指向window
                },3000)
            },2500)
        }
    }
    obj3.test()

</script>
</body>
</html>